#include "debug.h"
#include "../DDIC/AllDDIC.h"
#include "usbd_cdc.h"

u8 RM692AX_Gamma_R[68]=
{
	0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,
	0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2d,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3d,0x3f,
	0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47	
};
u8 RM692AX_Gamma_G[68]=
{
	0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64,0x65,0x66,
	0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0x80,0x81,0x82,0x83,0x84,
	0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c
};
u8 RM692AX_Gamma_B[68]=
{
	0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,0xa0,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa9,0xaa,0xab,0xac,
	0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,
	0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2	
};
u8 RM692AX_Gamma_R_TS[68]=
{
	0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2d,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3d,0x3f,
	0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,
	0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47
};
u8 RM692AX_Gamma_G_TS[68]=
{
	0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0x80,0x81,0x82,0x83,0x84,
	0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64,0x65,0x66,
	0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c
};
u8 RM692AX_Gamma_B_TS[68]=
{
	0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,
	0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,0xa0,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa9,0xaa,0xab,0xac,
	0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2
};

u8 RM692AX_Gamma_Points[33] =
{
	 0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,
	 0x51,0x52,0x53,0x54,0x55,0x56,0x58,0x59,
	 0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,
	 0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69
};

u8 RM692AX_otptime=0;
u8 RM692AX_Gray[33] =
{	//绑点位置～
	 0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x58,0x59,0x5a,0x5b,0x5c,0x5d,
	 0x5e,0x5f,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69
};
u8 Read_Register(u8 SigMode ,u8 channel,u8 cmd)
{
		u8 buffer1[3];
    u8 Redata;
    SSD2828_W_Reg(SigMode,channel,0xC1,0x0002);                                
    buffer1[0] = 0x01;
    buffer1[1] = cmd;
    SSD2828_W_Array(SigMode,channel,buffer1,0); 
    delay_ms(15);
    Redata=SSD2828_R_Reg(SigMode,channel,0xFF);
		return Redata;
}


void RM692Ax_Write_Register(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    //SSD2828_W_Reg(SigMode,channel,0xB7,(LP_B7_Data&0xFBFF)|0x0400); 
		SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);		
    delay_ms(5);	
		SSD2828_W_Array(SigMode,channel,buffer,2);
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    delay_ms(5);
    buffer[4] = Uart_Error_None;
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写寄存器状态  ：ok
}
void RM692AX_Write_Register(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)	
{
    SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0010)&0XFFfd);
    delay_ms(15); 
    SSD2828_W_Array(SigMode,channel,buffer,2);
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    delay_ms(5);
    buffer[4] = Uart_Error_None;
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写寄存器状态  ：ok
}

void RM692Ax_Read_Register(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    //u8 buffer1[2];
	//SSD2828_W_Reg(SigMode,channel,0xB7,((HS_B7_Data|0x0010)&0XFFFD)|0x0080);  //bit7 1:读操作 bit4 1：HS CLOCK Disable
    SSD2828_W_Reg(SigMode,channel,0xB7,0x07C0);
	delay_ms(5);
	Mipi_Read(pdev,SigMode,channel,buffer[3],buffer[2]-1,Buffer_ReadCode);
	memcpy(buffer+4,Buffer_ReadCode,buffer[2]-1);
	
	SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	buffer[1]=2;  //0x22,0x02 共用串口返回数据处理部分
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3); 
}

void RM692Ax_Write_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[5];
    SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0010)&0XFFfd);
		delay_ms(2);
	
		buffer1[0] = 0x02;	
		buffer1[1] = 0xFE;
		buffer1[2] = 0x70;                // 强切gamma1
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[1] = 0x71;
		buffer1[2] = 0x00;                // 强切gamma1
		SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[1] = 0x72;
		buffer1[2] = 0x31;                // 强切gamma1
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		
    if((buffer[3]&0x03) == 0x00)
    {
        buffer1[1] = 0xFE;
        buffer1[2] = 0x50;                // GAMMA1  page1
        SSD2828_W_Array(SigMode,channel,buffer1,0);
    }
    else if((buffer[3]&0x03) == 0x01)
    {
        buffer1[1] = 0xFE;
        buffer1[2] = 0x52;                // GAMMA2  page7
        SSD2828_W_Array(SigMode,channel,buffer1,0);
    }   
    else if((buffer[3]&0x03) == 0x02)
    {
        buffer1[1] = 0xFE;
        buffer1[2] = 0x54;                // GAMMA3  page8
        SSD2828_W_Array(SigMode,channel,buffer1,0);
    }
	else if((buffer[3]&0x03) == 0x03)
    {
        buffer1[1] = 0xFE;
        buffer1[2] = 0x56;                // GAMMA3  page8
        SSD2828_W_Array(SigMode,channel,buffer1,0);
    }
    for( i = 0;i<buffer[2]-1;i++) 
    {	 
        if((buffer[3]&0xf0)==0x00)	
            SSD2828_W_Reg(SigMode,channel,0xBF,(u16)(buffer[i+4]<<8)|RM692AX_Gamma_R[i]);  
        else if((buffer[3]&0xf0)==0x40)
            SSD2828_W_Reg(SigMode,channel,0xBF,(u16)(buffer[i+4]<<8)|RM692AX_Gamma_G[i]); 
        else if((buffer[3]&0xf0)==0x80)
            SSD2828_W_Reg(SigMode,channel,0xBF,(u16)(buffer[i+4]<<8)|RM692AX_Gamma_B[i]); 																		
        delay_ms(2);
    }
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    buffer[4] = Uart_Error_None;
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写Gamma状态  ：ok  
}
void RM692AX_M2_Write_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{   
    u8 buffer1[5];
    SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0010)&0XFFfd);
	delay_ms(5);
    if((buffer[3]&0x03) == 0x00)
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);     //UCS 
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x50;                // GAMMA1  page1
        SSD2828_W_Array(SigMode,channel,buffer1,0);
    }
    else if((buffer[3]&0x03) == 0x01)
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x52;                // GAMMA2  page7
        SSD2828_W_Array(SigMode,channel,buffer1,0);
    }   
    else if((buffer[3]&0x03) == 0x02)
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x54;                // GAMMA3  page8
        SSD2828_W_Array(SigMode,channel,buffer1,0);
    }
	else if((buffer[3]&0x03) == 0x03)
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x56;                // GAMMA3  page8
        SSD2828_W_Array(SigMode,channel,buffer1,0);
    }
	else
	{
		buffer[4] = Uart_Error_Oth;
		STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写Gamma状态  ：ok  				
		goto RM69350_w_end;
	}
    for( i = 0;i<buffer[2]-1;i++) 
    {	 
        if((buffer[3]&0xf0)==0x00)	
            SSD2828_W_Reg(SigMode,channel,0xBF,(u16)(buffer[i+4]<<8)|RM692AX_Gamma_R[i]);  
        else if((buffer[3]&0xf0)==0x40)
            SSD2828_W_Reg(SigMode,channel,0xBF,(u16)(buffer[i+4]<<8)|RM692AX_Gamma_G[i]); 
        else if((buffer[3]&0xf0)==0x80)
            SSD2828_W_Reg(SigMode,channel,0xBF,(u16)(buffer[i+4]<<8)|RM692AX_Gamma_B[i]); 																		
        delay_ms(3);
    }
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    buffer[4] = Uart_Error_None;
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写Gamma状态  ：ok  
	RM69350_w_end: ;
}
void RM692Ax_Read_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[3];
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		delay_ms(10);
	
		buffer1[0] = 0x02;	
		buffer1[1] = 0xFE;
		buffer1[2] = 0x00;      
    if(buffer[4] == 0x01)      //Gamma1
    {			
        buffer1[1] = 0xFE;
			  buffer1[2] = 0x50;      // GAMMA1  page1
        SSD2828_W_Array(SigMode,channel,buffer1,0); 
    }
    else if(buffer[4] == 0x02) //Gamma2
    {
        buffer1[1] = 0xFE;       
        buffer1[2] = 0x52;      // GAMMA2  page7
        SSD2828_W_Array(SigMode,channel,buffer1,0); 
    }
    else if(buffer[4] == 0x03) //Gamma3
    {
        buffer1[1] = 0xFE;        
        buffer1[2] = 0x54;      // GAMMA3  page8
        SSD2828_W_Array(SigMode,channel,buffer1,0); 
    }
		else if (buffer[4] ==0x04)
		{
        buffer1[1] = 0xFE;        
        buffer1[2] = 0x56;      // GAMMA3  page8
        SSD2828_W_Array(SigMode,channel,buffer1,0); 
		}
		delay_ms(5);		
    SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
		delay_ms(5);				
		SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); 
    SSD2828_W_Reg(SigMode,channel,0xBC,0x0001);			
    for( i = 0;i<buffer[2]-1;i++)			 	
    {  	                              
        buffer1[0] = 0x01;
        buffer1[1] = (buffer[3]==0x00) ? RM692AX_Gamma_R[i] : ((buffer[3]==0x01) ? RM692AX_Gamma_G[i] : RM692AX_Gamma_B[i]);
        SSD2828_W_Array(SigMode,channel,buffer1,0); 
				delay_ms(6);
        buffer[4+i]=SSD2828_R_Reg(SigMode,channel,0xFF);        
    }
    delay_ms(5);
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 读取的 Gamma数据  ：ok  
}


void RM692AX_M2_AutoGamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	  u8 buffer1[3];
	
		//SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
    SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0010)&0XFFFD);

	buffer1[0] = 0x02;	
	buffer1[1] = 0xFE;
	buffer1[2] = 0x70;                // 强切gamma1
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	buffer1[1] = 0x71;
	buffer1[2] = 0x00;                // 强切gamma1
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	buffer1[1] = 0x72;
	buffer1[2] = 0x31;                // 强切gamma1
	SSD2828_W_Array(SigMode,channel,buffer1,0);		
	
		buffer1[0] = 0x02;	
		buffer1[1] = 0xFE;
		buffer1[2] = 0x50;                
		SSD2828_W_Array(SigMode,channel,buffer1,0);		
//    if((buffer[3]&0x03) == 0x00)
//    {
//        buffer1[1] = 0xFE;
//        buffer1[2] = 0x50;                // GAMMA1  page1
//        SSD2828_W_Array(SigMode,channel,buffer1,0);
//    }
//    else if((buffer[3]&0x03) == 0x01)
//    {
//        buffer1[1] = 0xFE;
//        buffer1[2] = 0x52;                // GAMMA2  page7
//        SSD2828_W_Array(SigMode,channel,buffer1,0);
//    }   
//    else if((buffer[3]&0x03) == 0x02)
//    {
//        buffer1[1] = 0xFE;
//        buffer1[2] = 0x54;                // GAMMA3  page8
//        SSD2828_W_Array(SigMode,channel,buffer1,0);
//    }
//		 else if((buffer[3]&0x03) == 0x03)
//    {
//        buffer1[1] = 0xFE;
//        buffer1[2] = 0x56;                // GAMMA3  page8
//        SSD2828_W_Array(SigMode,channel,buffer1,0);
//    }
		
		SSD2828_W_Reg(SigMode,channel,0xBC,0x02);
    for( i = 0;i<buffer[2];i++) 
    {	 
			SSD2828_W_Reg(SigMode,channel,0xBF,(u16)(buffer[i+4]<<8)|buffer[i+3]);  
			i++;
			delay_ms(2);
    }				
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
}

void RM692AX_M2_Read_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[3];
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	delay_ms(15);
	buffer1[0] = 0x02;
    if(buffer[4] == 0x01)      //Gamma1
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);     
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
			  buffer1[2] = 0x50;      // GAMMA1  page1
        SSD2828_W_Array(SigMode,channel,buffer1,0); 
    }
    else if(buffer[4] == 0x02) //Gamma2
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;       
        buffer1[2] = 0x52;      // GAMMA2  page7
        SSD2828_W_Array(SigMode,channel,buffer1,0); 
    }
    else if(buffer[4] == 0x03) //Gamma3
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);	        
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;        
        buffer1[2] = 0x54;      // GAMMA3  page8
        SSD2828_W_Array(SigMode,channel,buffer1,0); 
    }
	else if (buffer[4] ==0x04)
	{
		buffer1[0] = 0x02;
	buffer1[1] = 0xFE;
	buffer1[2] = 0x00;
	SSD2828_W_Array(SigMode,channel,buffer1,0);	      
	buffer1[0] = 0x02;
	buffer1[1] = 0xFE;        
	buffer1[2] = 0x56;      // GAMMA3  page8
	SSD2828_W_Array(SigMode,channel,buffer1,0); 
	}
	else
	{
		buffer[4] = Uart_Error_Oth;
		STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写Gamma状态  ：ok  				
		goto RM69350_r_end;
	}		
	delay_ms(15);		
    SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); 
    SSD2828_W_Reg(SigMode,channel,0xBC,0x0001);	
    for( i = 0;i<buffer[2]-1;i++)			 	
    {  	
        SSD2828_W_Reg(SigMode,channel,0xC1,0x0002);                                
        buffer1[0] = 0x01;
        buffer1[1] = (buffer[3]==0x00) ? RM692AX_Gamma_R[i] : ((buffer[3]==0x42) ? RM692AX_Gamma_G[i] : RM692AX_Gamma_B[i]);
        SSD2828_W_Array(SigMode,channel,buffer1,0); 
				delay_ms(6);
        buffer[4+i]=SSD2828_R_Reg(SigMode,channel,0xFF);        
    }	
    delay_ms(5);
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 读取的 Gamma数据  ：ok  
	RM69350_r_end: ;
}

void RM692Ax_Gamma_Mapping(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		u8 buffer1[5];
		SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0010)&0XFFfd);
		delay_ms(5);
		buffer1[0] = 0x02;
		buffer1[1] = 0xfe;
		buffer1[2] = 0x70;
		SSD2828_W_Array(SigMode,channel,buffer1,0);
	
		buffer1[1] = 0x48;
		buffer1[2] = buffer[3];
		SSD2828_W_Array(SigMode,channel,buffer1,0);		
	
		for( i = 1;i<buffer[2];i++) 
		{	 
			SSD2828_W_Reg(SigMode,channel,0xBF,(u16)(buffer[i+3]<<8)|RM692AX_Gamma_Points[i]);   																	
			delay_ms(1);
		}
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		buffer[4] = Uart_Error_None;
		STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写Gamma状态  ：ok  		

}



void RM692Ax_Gamma_OTP_Start(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		u8 buffer1[5];
		//u8 R_30,R_31,R_32,R_33,R_34,R_35,R_36,R_E6,R_E7;
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		delay_ms(5);
	/*
		buffer1[0] = 0x02;
		buffer1[1] = 0xfe;
		buffer1[2] = 0xD0;
		SSD2828_W_Array(SigMode,channel,buffer1,0); 	
		R_E6=Read_Register(SigMode,channel,0xE6);
		R_E7=Read_Register(SigMode,channel,0xE7);	
		buffer1[0] = 0x02;
		buffer1[1] = 0xfe;
		buffer1[2] = 0x44;
		SSD2828_W_Array(SigMode,channel,buffer1,0); 		
		R_30=Read_Register(SigMode,channel,0x30);
		R_31=Read_Register(SigMode,channel,0x31);
		R_32=Read_Register(SigMode,channel,0x32);
		R_33=Read_Register(SigMode,channel,0x33);
		R_34=Read_Register(SigMode,channel,0x34);
		R_35=Read_Register(SigMode,channel,0x35);	
		R_36=Read_Register(SigMode,channel,0x36);
*/
		if(buffer[4]==6) //RCN
		{
			buffer1[0] = 0x02;
			buffer1[1] = 0xFE;
			buffer1[2] = 0xD0;
			SSD2828_W_Array(SigMode,channel,buffer1,0);  				
			buffer1[0] = 0x02;
			buffer1[1] = 0x99;
			buffer1[2] = 0x20;
			SSD2828_W_Array(SigMode,channel,buffer1,0);  	
			buffer1[0] = 0x02;
			buffer1[1] = 0xFE;
			buffer1[2] = 0x40;
			SSD2828_W_Array(SigMode,channel,buffer1,0);  		
			buffer1[0] = 0x02;
			buffer1[1] = 0x9A;
			buffer1[2] = 0x00;
			SSD2828_W_Array(SigMode,channel,buffer1,0);  								
		}

    buffer1[0] = 0x02;
    buffer1[1] = 0xFE;
    buffer1[2] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);  		

		buffer1[0] = 0x01;
		buffer1[1] = 0x28;
		SSD2828_W_Array(SigMode,channel,buffer1,0); 	
		delay_ms(50);
		buffer1[0] = 0x01;
		buffer1[1] = 0x10;
		SSD2828_W_Array(SigMode,channel,buffer1,0); 	
		delay_ms(50);	
    buffer1[0] = 0x02;
    buffer1[1] = 0xFE;
    buffer1[2] = 0x40;
    SSD2828_W_Array(SigMode,channel,buffer1,0);     //Page0
    delay_ms(50);
    buffer1[0] = 0x02;
    buffer1[1] = 0xF2;
    buffer1[2] = 0x01;
    SSD2828_W_Array(SigMode,channel,buffer1,0);     //Page0			
	  delay_ms(100);

		if(buffer[4]==1)//GAM1-50H
		{
			buffer1[0] = 0x02;
			if(buffer[5]==1) //gamma1
			{
				buffer1[1] = 0xEE;
				buffer1[2] = 0x01;
			}
			else if(buffer[5]==5) //gamma5
			{
				buffer1[1] = 0xEE;
				buffer1[2] = 0x10;		
			}
			else if(buffer[5]==9) //gamma9
			{
				buffer1[1] = 0xED;
				buffer1[2] = 0x01;		
			}
			else if(buffer[5]==13) //gamma13
			{
				buffer1[1] = 0xED;
				buffer1[2] = 0x10;	
			}
			SSD2828_W_Array(SigMode,channel,buffer1,0);					
		}
//---------------------------------------------------		
		else if(buffer[4]==2)//52
		{
			buffer1[0] = 0x02;
			if(buffer[5]==2) //gamma2
			{							
				buffer1[1] = 0xEE;
				buffer1[2] = 0x02;
			}
			else if(buffer[5]==6) //gamma6
			{
				buffer1[1] = 0xEE;
				buffer1[2] = 0x20;	
			}
			else if(buffer[5]==10)//gamma10
			{
				buffer1[1] = 0xED;
				buffer1[2] = 0x02;			
			}
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
		}
		else if(buffer[4]==3)//GAM1-54H	
		{
			buffer1[0] = 0x02;
			if(buffer[5]==3) //gamma3
			{				
				buffer1[1] = 0xEE;
				buffer1[2] = 0x04;   
			}
			else if(buffer[5]==7) //gamma7
			{
				buffer1[1] = 0xEE;
				buffer1[2] = 0x40;   		
			}
			SSD2828_W_Array(SigMode,channel,buffer1,0);		
		}
		else if(buffer[4]==4)//GAM1-56H	
		{
			buffer1[0] = 0x02;
			if(buffer[5]==4) //gamma4
			{	
				buffer1[1] = 0xEE;
				buffer1[2] = 0x08;
			}
			else if(buffer[5]==8) //gamma8
			{
				buffer1[1] = 0xEE;
				buffer1[2] = 0x80;		
			}
			SSD2828_W_Array(SigMode,channel,buffer1,0);	
		}
		
		else if(buffer[4]==5)//P-40H,P-60H,P-70H,P-90H,A0,D0,72H,74H,10h,82h
		{
			buffer1[0] = 0x02;			
			if(buffer[3]==1) //time1
			{
				buffer1[1] = 0xF6;
				buffer1[2] = 0xAD;
				SSD2828_W_Array(SigMode,channel,buffer1,0);	
				buffer1[1] = 0xF8;  //72
				buffer1[2] = 0x20;
				SSD2828_W_Array(SigMode,channel,buffer1,0);					
				buffer1[1] = 0xEC;  //74
				buffer1[2] = 0x08;
				SSD2828_W_Array(SigMode,channel,buffer1,0);	
				buffer1[1] = 0xED;  //82
				buffer1[2] = 0x40;
				SSD2828_W_Array(SigMode,channel,buffer1,0);					
				buffer1[1] = 0xF0;  //92
				buffer1[2] = 0x40;
				SSD2828_W_Array(SigMode,channel,buffer1,0);	
				buffer1[1] = 0xF6;  //E0
				buffer1[2] = 0x40;
				SSD2828_W_Array(SigMode,channel,buffer1,0);					
				buffer1[1] = 0xFE;
				buffer1[2] = 0xD0;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 
				buffer1[1] = 0xE5;
				buffer1[2] = 0x03;
				SSD2828_W_Array(SigMode,channel,buffer1,0);	
			}
			else if(buffer[3]==2) //TIME2
			{
				buffer1[1] = 0xF7;
				buffer1[2] = 0xAD;
				SSD2828_W_Array(SigMode,channel,buffer1,0);					
				buffer1[1] = 0xED;  //82
				buffer1[2] = 0x80;
				SSD2828_W_Array(SigMode,channel,buffer1,0);		
				buffer1[1] = 0xF9;  //72
				buffer1[2] = 0x20;
				SSD2828_W_Array(SigMode,channel,buffer1,0);					
				buffer1[1] = 0xEC;  //74
				buffer1[2] = 0x10;
				SSD2828_W_Array(SigMode,channel,buffer1,0);	
				buffer1[1] = 0xF0;  //92
				buffer1[2] = 0x20;
				SSD2828_W_Array(SigMode,channel,buffer1,0);					
				buffer1[1] = 0xF7;  //E0
				buffer1[2] = 0x40;
				SSD2828_W_Array(SigMode,channel,buffer1,0);					
				buffer1[1] = 0xFE;  
				buffer1[2] = 0xD0;
				SSD2828_W_Array(SigMode,channel,buffer1,0); 
				buffer1[1] = 0xE4;
				buffer1[2] = 0x03;
				SSD2828_W_Array(SigMode,channel,buffer1,0);		

			}
		}
		else if(buffer[4]==6)//20\22\26
		{
			if(buffer[3]==1)
			{	
				buffer1[1] = 0xF8;
				buffer1[2] = 0x16;
				SSD2828_W_Array(SigMode,channel,buffer1,0);	
			}
			else if(buffer[3]==2)
			{
				buffer1[1] = 0xF9;
				buffer1[2] = 0x16;
				SSD2828_W_Array(SigMode,channel,buffer1,0);	
			}
		}
		else if(buffer[4]==7)//RCN
		{
			if(buffer[3]==1)
			{				
				buffer1[1] = 0xFE;
				buffer1[2] = 0x40;
				SSD2828_W_Array(SigMode,channel,buffer1,0);				
				buffer1[1] = 0xF8;
				buffer1[2] = 0x40;
				SSD2828_W_Array(SigMode,channel,buffer1,0);
			}
			else if(buffer[3]==2)
			{
				buffer1[1] = 0xFE;
				buffer1[2] = 0x40;
				SSD2828_W_Array(SigMode,channel,buffer1,0);				
				buffer1[1] = 0xF8;
				buffer1[2] = 0x80;
				SSD2828_W_Array(SigMode,channel,buffer1,0);			
			}
		}
//----------------
		buffer1[0] = 0x02;
    buffer1[1] = 0xFE;
    buffer1[2] = 0x40;
    SSD2828_W_Array(SigMode,channel,buffer1,0);     //Page0
    delay_ms(50);
    buffer1[0] = 0x02;//MTPCTR
    buffer1[1] = 0xF2;
    buffer1[2] = 0x01;
    SSD2828_W_Array(SigMode,channel,buffer1,0);    
    buffer1[0] = 0x02;
    buffer1[1] = 0xF3;
    buffer1[2] = 0xA5;
    SSD2828_W_Array(SigMode,channel,buffer1,0);  
    buffer1[0] = 0x02;
    buffer1[1] = 0xF4;
    buffer1[2] = 0x5A;
    SSD2828_W_Array(SigMode,channel,buffer1,0);  
    buffer1[0] = 0x02;
    buffer1[1] = 0xF5;
    buffer1[2] = 0x3C;
    SSD2828_W_Array(SigMode,channel,buffer1,0);  		
    delay_ms(1200);         // wait for >400 ms   
    buffer[4] = Uart_Error_None;
    buffer[1] = 0x07;
	  buffer[2] = 0x03;	
    buffer[0] = 0x3E;		
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写OTP状态  ：ok		
		
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);		
}

void RM672AX_M2_Read_OTP_Time(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	  u8 buffer1[3];
    u16 ED_D,EE_D,EB_D,EC_D,E9_D,E8_D,E7_D,E6_D;
    u8 RM692AX_otptime = 0;
    if(SigMode != CMD_Mode)
	  delay_ms(5);
		buffer1[0] = 0x02;
    buffer1[1] = 0xFE;
    buffer1[2] = 0x40;
    SSD2828_W_Array(SigMode,channel,buffer1,0);     // Page 0  与69300不一致
    buffer1[0] = 0x02;
    buffer1[1] = 0xE5;
    buffer1[2] = 0x02;
    SSD2828_W_Array(SigMode,channel,buffer1,0);     // otp_load_en   与69300一致 														
    buffer1[0] = 0x02;
    buffer1[1] = 0xF2;
    buffer1[2] = 0x80;
    SSD2828_W_Array(SigMode,channel,buffer1,0);     // Margin Read Check   与69300一致
		delay_ms(50);
		buffer1[0] = 0x02;
		buffer1[1] = 0xfe;
		buffer1[2] = 0x44;
		SSD2828_W_Array(SigMode,channel,buffer1,0); 
    SSD2828_W_Reg(SigMode,channel,0xB7,((HS_B7_Data|0x0010)&0XFFFD)|0x0080);      
    delay_ms(100);
    buffer1[0] = 0x01;
    buffer1[1] = 0x36;         //与69300有区别
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    delay_ms(20);
    if(SigMode == Video_Mode)  //RGB+SPI= MIPI  
    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);							
    delay_ms(5);                                  
    EE_D=SSD2828_R_Reg(SigMode,channel,0xFF); 
    delay_ms(100);		
    buffer1[0] = 0x01;
    buffer1[1] = 0x35;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    delay_ms(20);
    if(SigMode == Video_Mode)  //RGB+SPI= MIPI  
    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);							
    delay_ms(5);                             
    ED_D=SSD2828_R_Reg(SigMode,channel,0xFF);
		delay_ms(100);
	  buffer1[0] = 0x01;
    buffer1[1] = 0x34;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    delay_ms(20);
    if(SigMode == Video_Mode)  //RGB+SPI= MIPI  
    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);							
    delay_ms(5);                             
    EC_D=SSD2828_R_Reg(SigMode,channel,0xFF);

	buffer1[0] = 0x01;
    buffer1[1] = 0xE7;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    delay_ms(20);
    if(SigMode == Video_Mode)  //RGB+SPI= MIPI  
    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);							
    delay_ms(5);                             
    E7_D=SSD2828_R_Reg(SigMode,channel,0xFF);
	
	buffer1[0] = 0x01;
    buffer1[1] = 0xE6;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    delay_ms(20);
    if(SigMode == Video_Mode)  //RGB+SPI= MIPI  
    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);							
    delay_ms(5);                             
    E6_D=SSD2828_R_Reg(SigMode,channel,0xFF);
	
	if(buffer[3] == 0x00||buffer[3] == 0x01||buffer[3] == 0x02||buffer[3] == 0x03||buffer[3]==0x04)
	{
		if(buffer[3] == 0x00)       //读取gamma1次数
    {
        if(EE_D&0X01)
            RM692AX_otptime = 1;
        if(ED_D&0X01)
            RM692AX_otptime = 2;
				if(EC_D&0X01)
            RM692AX_otptime = 3;
    }
    else if(buffer[3] == 0x01)  //读取gamma2次数
    {
        if(EE_D&0X02)
            RM692AX_otptime = 1; 
        if(ED_D&0X02)
            RM692AX_otptime = 2;   
		    if(EC_D&0X02)
            RM692AX_otptime = 3; 			
    }
    else if(buffer[3] == 0x02)  //读取gamma3次数
    {
        if(EE_D&0X04)
            RM692AX_otptime = 1;
        if(ED_D&0X04)
            RM692AX_otptime = 2; 
				if(EC_D&0X04)
            RM692AX_otptime = 3; 				
    }
    else if(buffer[3] == 0x03)  //读取Gamma4次数
    {
        if(EE_D&0X08)
            RM692AX_otptime = 1;
        if(ED_D&0X08)
            RM692AX_otptime = 2;  
        if(EC_D&0X08)
            RM692AX_otptime = 3;        
    }
	else if(buffer[3] ==0x04)
	{
		if(E7_D&0X03)
            RM692AX_otptime = 1;
        if(E6_D&0X03)
            RM692AX_otptime = 2;
	}
	}
    buffer[4]=RM692AX_otptime;
    RM692AX_otptime=0x00;
    delay_ms(5);
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    buffer[3] = Uart_Error_None;
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 读取的OTP数据  ：ok  
}

void RM692AX_Change_Gray(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	u8 buffer1[5];
	SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0010)&0XFFfd);
	delay_ms(5);
	buffer1[0] = 0x02;
	buffer1[1] = 0xfe;
	buffer1[2] = 0x70;
	SSD2828_W_Array(SigMode,channel,buffer1,0);
	for( i = 0;i<buffer[2];i++) 
	{	 
		SSD2828_W_Reg(SigMode,channel,0xBF,(u16)(buffer[i+3]<<8)|RM692AX_Gray[i]);   																	
		delay_ms(3);
	}
	SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	buffer[4] = Uart_Error_None;
	STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写Gamma状态  ：ok  
}
void RM692AX_M2_Read_Gamma_TS(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[3];
	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	delay_ms(15);
	buffer1[0] = 0x02;
    if(buffer[4] == 0x01)      //Gamma1
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);     
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
			  buffer1[2] = 0x50;      // GAMMA1  page1
        SSD2828_W_Array(SigMode,channel,buffer1,0); 
    }
    else if(buffer[4] == 0x02) //Gamma2
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;       
        buffer1[2] = 0x52;      // GAMMA2  page7
        SSD2828_W_Array(SigMode,channel,buffer1,0); 
    }
    else if(buffer[4] == 0x03) //Gamma3
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);	        
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;        
        buffer1[2] = 0x54;      // GAMMA3  page8
        SSD2828_W_Array(SigMode,channel,buffer1,0); 
    }
	else if (buffer[4] ==0x04)
	{
		buffer1[0] = 0x02;
	buffer1[1] = 0xFE;
	buffer1[2] = 0x00;
	SSD2828_W_Array(SigMode,channel,buffer1,0);	      
	buffer1[0] = 0x02;
	buffer1[1] = 0xFE;        
	buffer1[2] = 0x56;      // GAMMA3  page8
	SSD2828_W_Array(SigMode,channel,buffer1,0); 
	}
	else
	{
		buffer[4] = Uart_Error_Oth;
		STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写Gamma状态  ：ok  				
		goto RM69350_r_end;
	}		
	delay_ms(15);		
    SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080); 
    SSD2828_W_Reg(SigMode,channel,0xBC,0x0001);	
    for( i = 0;i<buffer[2]-1;i++)			 	
    {  	
        SSD2828_W_Reg(SigMode,channel,0xC1,0x0002);                                
        buffer1[0] = 0x01;
        buffer1[1] = (buffer[3]==0x00) ? RM692AX_Gamma_R_TS[i] : ((buffer[3]==0x42) ? RM692AX_Gamma_G_TS[i] : RM692AX_Gamma_B_TS[i]);
        SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(6);
        buffer[4+i]=SSD2828_R_Reg(SigMode,channel,0xFF);        
    }	
    delay_ms(5);
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 读取的 Gamma数据  ：ok  
	RM69350_r_end: ;
}



void RM692AX_M2_Write_Gamma_TS(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[5];
    SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0010)&0XFFfd);
	delay_ms(5);
    if((buffer[3]&0x03) == 0x00)
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);     //UCS 
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x50;                // GAMMA1  page1
        SSD2828_W_Array(SigMode,channel,buffer1,0);
    }
    else if((buffer[3]&0x03) == 0x01)
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x52;                // GAMMA2  page7
        SSD2828_W_Array(SigMode,channel,buffer1,0);
    }   
    else if((buffer[3]&0x03) == 0x02)
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
        SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x54;                // GAMMA3  page8
        SSD2828_W_Array(SigMode,channel,buffer1,0);
    }
	else if((buffer[3]&0x03) == 0x03)
    {
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x00;
       SSD2828_W_Array(SigMode,channel,buffer1,0);
        buffer1[0] = 0x02;
        buffer1[1] = 0xFE;
        buffer1[2] = 0x56;                // GAMMA3  page8
        SSD2828_W_Array(SigMode,channel,buffer1,0);
    }
	else
	{
		buffer[4] = Uart_Error_Oth;
		STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写Gamma状态  ：ok  				
		goto RM69350_w_end;
	}
    for( i = 0;i<buffer[2]-1;i++) 
    {	 
        if((buffer[3]&0xf0)==0x00)	
            SSD2828_W_Reg(SigMode,channel,0xBF,(u16)(buffer[i+4]<<8)|RM692AX_Gamma_R_TS[i]);  
        else if((buffer[3]&0xf0)==0x40)
            SSD2828_W_Reg(SigMode,channel,0xBF,(u16)(buffer[i+4]<<8)|RM692AX_Gamma_G_TS[i]); 
        else if((buffer[3]&0xf0)==0x80)
            SSD2828_W_Reg(SigMode,channel,0xBF,(u16)(buffer[i+4]<<8)|RM692AX_Gamma_B_TS[i]); 																		
        delay_ms(3);
    }
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    buffer[4] = Uart_Error_None;
    STM2PC(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写Gamma状态  ：ok  
	RM69350_w_end: ;
}

void ProcessForIc3E( USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8 buffer[],u16 LP_B7_Data,u16 HS_B7_Data)
{	
	//void *pdev;
	switch(buffer[1])
	{
		case 0x51:
		case 0x01:                                      //写寄存器
				RM692Ax_Write_Register(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);
				break;
		case 0x02:                                      //读寄存器
		case 0x22:		
				RM692Ax_Read_Register(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);
				break;
		case 0x03:                                      //写Gamma
				RM692Ax_Write_Gamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);
				break;
		case 0x04:                                      //写Gamma
				RM692Ax_Read_Gamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);
				break;				
		case 0x06: 
				RM692Ax_Gamma_Mapping(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);	
				break;		
		case 0x07:                                      //读Gamma
				RM692Ax_Gamma_OTP_Start(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data); 
				break;
		case 0x08:   									//写Gamma数据
				RM692AX_M2_Write_Gamma(pdev,CDC_IN_EP,OLED.SigMode ,1,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);
				break;
		case 0x09:                                      //读Gamma数据
                RM692AX_M2_Read_Gamma(pdev,CDC_IN_EP,OLED.SigMode ,1,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);     break;
		case 0x0B://otp time read
				RM672AX_M2_Read_OTP_Time(pdev,CDC_IN_EP,OLED.SigMode ,1,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data); break;
		case 0x0C://otp time
                {
                    RM692AX_otptime=USB_Rx_Buffer[4];
                    USB_Rx_Buffer[4] = Uart_Error_None;
                    STM2PC(pdev,CDC_IN_EP,USB_Rx_Buffer,USB_Rx_Buffer[2]+3);           //返回 写Gamma状态  ：ok  
                }break;
		case 0x38:	  //特殊Gamma调整
				RM692AX_M2_Write_Gamma_TS(pdev,CDC_IN_EP,OLED.SigMode ,1,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);break;
		case 0x39:    //特殊读Gamma数据，对应高低交换寄存器地址
                RM692AX_M2_Read_Gamma_TS(pdev,CDC_IN_EP,OLED.SigMode ,1,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data); break;
		case 0xDD:   									// auto Gamma数据
			  RM692AX_M2_AutoGamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data); 
		break;			
		case 0xEE:	//设定绑点位置
				RM692AX_Change_Gray(pdev,CDC_IN_EP,OLED.SigMode ,1,USB_Rx_Buffer,LP_B7_Data,HS_B7_Data);break;
		default:break;
	}			
}




